#pragma once

// Copyright (c) 2010 Manuel Peinado Gallego <manuel.peinado@gmail.com>
// Distributed under the MIT license

// PickColor.h : interface of the PickColor class
//


#include "Color.h"

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// This class is used for picking computations. Every pickable object that
// is added to the main view is assigned a pick color (it won't be visible, 
// so which color is chosen does not really matter). Only the R and G 
// components are used, which means that we can distinguish between 2^16 
// different pickables (more than enough). However, some pickables like 
// to know which of their sub-parts was actually picked. This is where 
// the B component comes into play. When a pickable draws itself, it
// is forced to use the R,G components that it was assigned, but it has 
// the freedom to draw its different parts with different B components. 
// Later on if that pickable is actually picked (for which only R and G
// are taken into account), the engine will notify it of the B componetn
// at the clicked point. This way the pickable knows which part was 
// actually clicked. Pickables that are not interested in this information
// can simply leave the default value of B (255)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

class PickColor
{
public:

    // Only the first two elements are used. The B component is 255
    PickColor(GLubyte* rgb);

    // The B component is 255
    PickColor(GLubyte r=255, GLubyte g=255);

    // These operators only take into account the main components, R and G
    bool operator<(const PickColor& other) const;
    bool operator==(const PickColor& other) const;
    bool operator!=(const PickColor& other) const;

    PickColor& operator++();
    PickColor operator++(int);

    void setSecondaryComponent(GLubyte blue);
    
    void setInRenderContext() const;

private:
    // The components
    GLubyte rgb[3];
};
